const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  mode: "development",
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "./build"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        test: /.css$/,
        use: ["style-loader", "css-loader"],
      },
      // {
      //   test: /\.js$/,
      //   use: [
      //     "./my_loader/index.js",
      //     "./my_loader/my_loader1.js",
      //     "./my_loader/my_loader2.js",
      //     {
      //       loader: "./my_loader/my_loader3.js",
      //       options: {
      //         plugins: [],
      //         presets: [],
      //         name:"bob",
      //         age:18
      //       },
      //     },
      //   ],
      // },
      {
        test: /\.js$/,
        use: [
          {
            loader: "babel-loader",
            options: {
              plugins: ["@babel/plugin-transform-arrow-functions"],
            },
          },
        ],
      },
      {
        test: /\.md$/,
        use: [{ loader: "./markdown-loader/index.js" }],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: "自定义loader", //标签页对应的title
      template: "./index.html", //指定模板
    }), //生成html文档
  ],
  devServer: {
    compress: true, //是否压缩
    open: true, //是否打开浏览器
    static: ["public"],
    // hot: "only",
    proxy: {
      "/api": {
        target: "http://localhost:3000", //静态资源和api服务在同一台服务器上
        pathRewrite: {
          "/api": "",
        }, //重写路径
      },
      changeOrigin: true,
    },

    historyApiFallback: true,
  },
};
